#ifndef EM80_LED_CONFIG_HPP
#define EM80_LED_CONFIG_HPP

#include "../packet_base.hpp"
#include "../payload_headers.hpp"
#include "../../v8stdint.h"

#include <memory>

namespace em80_driver
{

class LEDConfig : public EM80PayloadBase
{
public:
    LEDConfig(EM80PacketPtr &packet) : EM80PayloadBase(packet, "LEDConfig", false, 1) {}

    struct Data
    {
        Data() : mode(0) {}
        uint8_t mode;
    };

    struct Mode
    {
        enum State
        {
            LEFT_TURN = 0,
            RIGHT_TURN,
            OFF,
            ALERT,
            FLUSH
        };
    };

    Data data;

    ~LEDConfig() {}

    //not to be used directly by external source
    bool serialize()
    {
        //TODO : is it directly control the raw data
        std::shared_ptr<Buffer> byteStream = std::make_shared<Buffer>(0);
        buildBytes(static_cast<uint8_t>(Header::LEDConfig), *byteStream);
        buildBytes(static_cast<uint8_t>(length), *byteStream);
        buildBytes(data.mode, *byteStream);
    
        int i = 0;

        for(auto iter = packet->payload(); iter != packet->payload() + length + 2; iter++, i++)
        {
            *iter = (*byteStream)[i];
        }

        return true;
    }

    bool deserialize()
    {
        std::vector<uint8_t> byteStream;

        byteStream.assign(packet->payload(), packet->payload() + static_cast<uint32_t>(length) + 2);


        //TODO: check them
        uint8_t header_id, length_packed;
        buildVariable(header_id, byteStream);
        buildVariable(length_packed, byteStream);
        buildVariable(data.mode, byteStream);

        return true;
    }
};

} // namespace em80_driver

#endif /* EM80_LED_CONFIG_HPP*/
